﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FantastPlatform.Core.Configurations;
using FantastPlatform.Core.Extensions;
using FantastPlatform.Core.JsonEntities;
using FantastPlatform.Core.Properties;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Text;
using System.Xml;
using System.IO;
using System.Reflection;
using FantastPlatform.Framework;
using FantastPlatform.Framework.Core;
using Yaxunsoft.CasesManagement;
using FantastPlatform.Framework.IModel;

namespace FantastPlatform.Decision.UI
{
    public partial class Main : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
       

        public string Menu()
        {
            List<JsonTreeNode> list = GetMenu();
            JavaScriptSerializer s = new JavaScriptSerializer();
            StringBuilder sb = new StringBuilder();
            s.Serialize(list, sb);
            //sb.Insert(0, "var menudata=");
            return sb.ToString();
        }

        public static List<JsonTreeNode> GetMenu()
        {
            string menuxml = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "MenuData.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(menuxml);
            var nodes = doc.DocumentElement.SelectNodes("/MenuData/Menu");
            return ConvertXmlNodeToJsonNode(nodes);
        }

        private static List<JsonTreeNode> ConvertXmlNodeToJsonNode(XmlNodeList nodes)
        {
            List<JsonTreeNode> treenodelist = new List<JsonTreeNode>();
            foreach (XmlNode node in nodes)
            {
                JsonTreeNode treenode = new JsonTreeNode();
                treenode.id = node.Attributes["id"].Value;
                treenode.text = node.Attributes["text"].Value;
                treenode.value = node.Attributes["url"].Value;
                treenode.isexpand = node.Attributes["isexpand"].Value == "true";
                treenode.showcheck = false;
                treenode.complete = true;
                treenode.hasChildren = node.ChildNodes != null && node.ChildNodes.Count > 0;

                if (treenode.hasChildren)
                {
                    treenode.ChildNodes.AddRange(ConvertXmlNodeToJsonNode(node.ChildNodes));
                }
                treenodelist.Add(treenode);
            }
            return treenodelist;
        }

        private string getPromptWorkLog(int policeId)
        {
           
            return null;
        }

      
       

        private DateTime? getWeekStartTime()
        {
            DateTime now = DateTime.Now;
            DayOfWeek weekDay = now.DayOfWeek;
            if (weekDay == 0)
                weekDay = DayOfWeek.Sunday;
            DateTime startTime = now.AddDays(-Convert.ToInt32(weekDay) + 1).Date;
            return startTime;
        }
    }
}